/*
 * ErrorDialog.java
 *
 * Created on September 8, 2005, 10:55 AM
 */
package com.bff.mpd.musicjukebox.ui;

import com.bff.mpd.musicjukebox.ui.components.MusicJDialog;
import com.bff.bjj.ui.component.BJJButton;
import com.bff.mpd.musicjukebox.ui.settings.PropertiesFrame;
import com.bff.mpd.utils.Utils;
import java.awt.Frame;
import java.awt.Toolkit;
import java.awt.Dimension;
import javax.swing.JFrame;

/**
 *
 * @author  Bill
 */
public class ErrorDialog extends MusicJDialog {

    private String errorMessage;
    private String message;
    private boolean showSettings;

    /** Creates new form ErrorDialog */
    public ErrorDialog(Frame frame, String message, Exception exception) {
        this(frame, message, exception, true);
    }

    public ErrorDialog(Frame frame, String message, Exception exception, boolean showSettingsScreen) {
        this(frame, message, exception.getMessage(), showSettingsScreen);
    }

    public ErrorDialog(Frame frame, String message, String errorMsg, boolean showSettingsScreen) {
        super(frame);
        setTitle("Error");
        this.errorMessage = errorMsg;
        this.message = message;
        this.showSettings = showSettingsScreen;
        initComponents();

        Toolkit tk = Toolkit.getDefaultToolkit();
        Dimension d = tk.getScreenSize();
        int heightScreen = d.height / 2;
        int widthScreen = d.width / 2;

        setLocation(widthScreen - (int) (getWidth() / 2), heightScreen - (int) (getHeight() / 2));
        setVisible(true);
    }

    /*
    ErrorDialog(Frame frame, String message) {
    this(frame, message, null);
    }
     */
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        lblError = new javax.swing.JLabel(message);
        btnOk = new javax.swing.JPanel();
        btnOK = new BJJButton();
        textAreaException = new javax.swing.JTextArea(errorMessage+"\nPlease Correct and Restart Jukebox!");

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Error");

        lblError.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lblError.setBorder(javax.swing.BorderFactory.createEmptyBorder(10, 10, 10, 10));
        lblError.setFocusable(false);
        lblError.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        lblError.setOpaque(true);
        getContentPane().add(lblError, java.awt.BorderLayout.NORTH);

        btnOK.setText("OK");
        btnOK.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnOKActionPerformed(evt);
            }
        });
        btnOk.add(btnOK);

        getContentPane().add(btnOk, java.awt.BorderLayout.SOUTH);

        textAreaException.setEditable(false);
        textAreaException.setBorder(javax.swing.BorderFactory.createEmptyBorder(20, 20, 20, 20));
        getContentPane().add(textAreaException, java.awt.BorderLayout.CENTER);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnOKActionPerformed
        this.dispose();
        if (showSettings) {
            //frame.dispose();
            JFrame propFrame = new PropertiesFrame(false);
            propFrame.setSize(600, 700);
            propFrame.setPreferredSize(new Dimension(600,700));
            Utils.centerFrame(propFrame);
            propFrame.setVisible(true);
        } else {
            System.exit(1);
        }
    }//GEN-LAST:event_btnOKActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnOK;
    private javax.swing.JPanel btnOk;
    private javax.swing.JLabel lblError;
    private javax.swing.JTextArea textAreaException;
    // End of variables declaration//GEN-END:variables
}
